package com.magicborrow.views;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;

import com.magicborrow.R;
import com.magicborrow.utils.ViewPressedUtil;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by ghost on 16/5/10.
 */
public class SelectorTimeDialog extends Dialog implements View.OnClickListener {
    private List<String> priceMode;
    private PickerView pv;
    private PickerView pv2;
    private List<String> data;
    private String currentNumber;
    private String currentPriceMode;

    public SelectorTimeDialog(Context context, List<String> priceMode) {
        super(context, R.style.picker_style);
        this.priceMode = priceMode;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.layout_selector_time_dialog);
        setCanceledOnTouchOutside(true);
        findViewById(R.id.v_top).setOnClickListener(this);
        findViewById(R.id.btn_cancel).setOnClickListener(this);
        findViewById(R.id.btn_cancel).setOnTouchListener(ViewPressedUtil.TouchPress);
        findViewById(R.id.btn_ok).setOnTouchListener(ViewPressedUtil.TouchPress);
        pv = (PickerView) findViewById(R.id.pv_number);
        pv2 = (PickerView) findViewById(R.id.pv_string);

        data = new ArrayList<>();
        for (int i = 0; i < 24; i++) {
            data.add("" + ((i + 13) > 24 ? i - 11 : i + 13));
        }
        pv2.setData(priceMode);
        pv.setData(data);
        currentNumber = data.get(data.size() / 2);
        currentPriceMode = priceMode.get(priceMode.size() / 2);
      /*  List<String> data2 = new ArrayList<>();
        data2.add("时");
        data2.add("天");*/

        //  setImmerseLayout();
        pv.setOnSelectListener(new PickerView.onSelectListener() {
            @Override
            public void onSelect(String text) {
                currentNumber = text;
            }
        });
        pv2.setOnSelectListener(new PickerView.onSelectListener() {
            @Override
            public void onSelect(String text) {
                currentPriceMode = text;
            }
        });


    }


    public void setOnOkClickListener(View.OnClickListener listener) {
        findViewById(R.id.btn_ok).setOnClickListener(listener);


    }

    public String getTimeNumber() {
        if (currentNumber == null)
            return "0";

        return currentNumber;
    }

    public String getCurrentPriceMode() {
        if (currentPriceMode == null)
            return "";
        return currentPriceMode;
    }


    @Override
    public void onClick(View v) {
        dismiss();
    }
}
